package com.uit.httt04.duongvanlam.facedetection.service;

import com.uit.httt04.duongvanlam.facedetection.activity.UnlockActivity;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;

public class Service_AfterBootComplete extends Service
{
	private String TAG = "Service_BootComplete";

	private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver()
	{
		@Override
		public void onReceive(Context context, Intent intent)
		{
			Log.d(TAG, "broadcastReceiver:onReceive(" + context.getPackageName() + "," + intent.getAction() + ")");
			if (intent.getAction().equalsIgnoreCase("android.intent.action.SCREEN_ON"))
			{
				Intent i = new Intent(context, UnlockActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(i);
			}
		}
	};

	public Service_AfterBootComplete()
	{
	}

	@Override
	public void onCreate()
	{
		IntentFilter filter = new IntentFilter();
		filter.addAction("android.intent.action.SCREEN_OFF");
		filter.addAction("android.intent.action.SCREEN_ON");
		registerReceiver(broadcastReceiver, filter);
	}

	@Override
	public void onDestroy()
	{
		unregisterReceiver(broadcastReceiver);
	}

	@Override
	public IBinder onBind(Intent intent)
	{
		return null;
	}
}
